'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let {
		data
	} = await uniCloud.httpclient.request("https://tool.lu/ip/", {
		dataType: "text"
	})
	//返回数据给客户端
	// return getTodayTime(0,1)
	return {
		"mpserverlessComposedResponse": true, // 使用阿里云返回集成响应是需要此字段为true
		"statusCode": 200,
		"headers": {},
		"body": data
	}
};

/**
 * 中国时差
 */
let timeZone = 8;

function getTodayTime(day = 0, check = false) {
	let time = new Date();
	time.setHours(0);
	time.setMinutes(0);
	time.setSeconds(0);
	time.setMilliseconds(0)
	if (check) {
		time.setHours(timeZone * -1);
	}
	if (day != 0) {
		time.setDate(time.getDate() + day);
	}
	return time.getTime();
}
